package com.xxadmin.common.vo;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.xxadmin.common.dto.PageInfoDTO;
import com.xxadmin.common.util.clone.CopyUtils;
import lombok.Data;

import java.util.List;

/**
 * 分页包装类
 * 
 * @author:chenming
 * @date:2018/8/10
 */
@Data
public class PageInfoVO<T> {

    /** 当前页 **/
    private Integer pageNum;

    /** 每页的数量 **/
    private Integer pageSize;

    /** 总记录数 **/
    private Long total;

     /** 总页数 **/
    private Integer pages;

     /** 结果集 **/
    private List<T> result;

    public PageInfoVO(){

    }

    /**
     * 将 List 里面的元素进行转换
     *
     * @author:chenming
     * @date:2018/8/10
     */
    public PageInfoVO(PageInfoDTO pageInfo, Class targetClass){
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.pages = pageInfo.getPages();
        this.result = CopyUtils.copyList(pageInfo.getResult(),targetClass);
        this.total = pageInfo.getTotal();
    }
}
